// ActionScript file
import flash.events.*;
import flash.utils.*;

import mx.collections.*;
import mx.effects.Fade;


[Bindable] 	public	var currentPhoto	: String;
			
			private	var photos        	: ArrayCollection;
			private var delay        	: uint;
			private var repeatCount    	: uint;
			private var timer        	: Timer;
			private var timerCounter	: uint;
			private var fadeInHome		: Fade;
			private var fadeInGall		: Fade;

public function initApp(): void {  
	
 	fadeInHome = new Fade(homeImage);   	
   	fadeInHome.alphaFrom = 0.0;
   	fadeInHome.alphaTo = 1.0;
   	fadeInHome.duration = 2500;
   	
   	fadeInGall = new Fade(galleryImage); 
   	fadeInGall.alphaFrom = 0.0;
   	fadeInGall.alphaTo = 1.0;
   	fadeInGall.duration = 2500;
   
    // photos setup
    photos = new ArrayCollection( new Array( "1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg","10.jpg","11.jpg") );

    // set delay and repeat. Repeat counter should equal the number of photos in the array
    delay = 7000;
    repeatCount = photos.length ;
   
    // timer setup
    timer = new Timer(delay, repeatCount)
   
    timer.addEventListener(TimerEvent.TIMER, timerHandler);
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
   
    timer.start();
   
    // current photo setup
    fadeInHome.play();
    fadeInGall.play();
    currentPhoto = new String(photos.getItemAt(timer.currentCount));  
	 
}


// change the photo every time the counter runs down
private function timerHandler( e:TimerEvent ) : void {   
    // TODO shouldn't necessarily need this if statement
    if ( e.target.currentCount < photos.length) {
    fadeInGall.play();
    fadeInHome.play();
    currentPhoto = String( photos.getItemAt( e.target.currentCount) );
    }
}


// restart the timer if all the photos have already been shown
private function onComplete( e:TimerEvent ) : void {
    timer.reset();
    timer.start();
    fadeInGall.play();
    fadeInHome.play();
    currentPhoto = String( photos.getItemAt( timer.currentCount ) );
}

private function submitForm( e : MouseEvent ) : void{
	srv.send();
	clearForm();
}

private function clearForm() : void{
	fname.text = "";
	lname.text = "";
	email.text = "";
	phone.text = "";
	zip.text = "";
	message.text = "";
}